﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Maticsoft.Web.Products
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                       
        }

        		protected void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtProductId.Text))
			{
				strErr+="产品ID格式错误！\\n";	
			}
			if(this.txtProductName.Text.Trim().Length==0)
			{
				strErr+="产品名称不能为空！\\n";	
			}
			if(this.txtProductType.Text.Trim().Length==0)
			{
				strErr+="产品类型不能为空！\\n";	
			}
			if(this.txtDescription.Text.Trim().Length==0)
			{
				strErr+="产品描述不能为空！\\n";	
			}
			if(this.txtInterestRate.Text.Trim().Length==0)
			{
				strErr+="利率不能为空！\\n";	
			}
			if(this.txtStartDate.Text.Trim().Length==0)
			{
				strErr+="开始日期不能为空！\\n";	
			}
			if(this.txtEndDate.Text.Trim().Length==0)
			{
				strErr+="结束日期不能为空！\\n";	
			}
			if(!PageValidate.IsDecimal(txtMinimumInvestment.Text))
			{
				strErr+="最低投资额格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtMaximumInvestment.Text))
			{
				strErr+="最高投资额格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtCurrentValue.Text))
			{
				strErr+="当前价值格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtInvestmentReturn.Text))
			{
				strErr+="投资回报格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int ProductId=int.Parse(this.txtProductId.Text);
			string ProductName=this.txtProductName.Text;
			string ProductType=this.txtProductType.Text;
			string Description=this.txtDescription.Text;
			string InterestRate=this.txtInterestRate.Text;
			string StartDate=this.txtStartDate.Text;
			string EndDate=this.txtEndDate.Text;
			decimal MinimumInvestment=decimal.Parse(this.txtMinimumInvestment.Text);
			decimal MaximumInvestment=decimal.Parse(this.txtMaximumInvestment.Text);
			decimal CurrentValue=decimal.Parse(this.txtCurrentValue.Text);
			decimal InvestmentReturn=decimal.Parse(this.txtInvestmentReturn.Text);

			Maticsoft.Model.Products model=new Maticsoft.Model.Products();
			model.ProductId=ProductId;
			model.ProductName=ProductName;
			model.ProductType=ProductType;
			model.Description=Description;
			model.InterestRate=InterestRate;
			model.StartDate=StartDate;
			model.EndDate=EndDate;
			model.MinimumInvestment=MinimumInvestment;
			model.MaximumInvestment=MaximumInvestment;
			model.CurrentValue=CurrentValue;
			model.InvestmentReturn=InvestmentReturn;

			Maticsoft.BLL.Products bll=new Maticsoft.BLL.Products();
			bll.Add(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","add.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
